﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DiArte.Data.Catalog
{
    public class ProductImageDal : BaseDal
    {
        /// <summary>
        /// Deletes all product\image relations
        /// </summary>
        public void DeleteAll()
        {
            using (var command = new Npgsql.NpgsqlCommand("DELETE FROM product_image"))
                PerformCommand(command);
        }

        /// <summary>
        /// Inserts a new product image
        /// </summary>
        /// <param name="productId">The product id</param>
        /// <param name="language">The language</param>
        /// <param name="type">The image type</param>
        /// <param name="url">The image url</param>
        public void Insert(int productId, String language, String type, String url)
        {
            using (var command = new Npgsql.NpgsqlCommand("INSERT INTO product_image(product_image_id, product_id, language, type, url) VALUES " +
                "(nextval('product_image_id_sequence'), :product_id, :language, :type, :url)"))
            {
                command.Parameters.AddWithValue("product_id", productId);
                command.Parameters.AddWithValue("language", language);
                command.Parameters.AddWithValue("type", type);
                command.Parameters.AddWithValue("url", url);

                PerformCommand(command);
            }
        }

    }
}
